<template>
	<view class="chenjian-body tn-padding-top tn-padding-sm">
		<view class="tn-padding-top-sm">
			 
		</view>
		<view class="tn-flex tn-flex-row-center tn-margin-bottom-sm">
			<view class="justify-content-item">
				<text @touchend="getPreMonth()">上个月</text>
			</view>
			<view class="justify-content-item tn-flex-1 tn-text-center">
				<text class="center-text-riqi tn-padding-right-sm" @click="showcalFunction">{{dangqianriqi}}</text>
			</view>
			<view class="justify-content-item">
				<text @touchend="getNextMonth()">下个月</text>
			</view>
		</view>
			<view class="titlev tn-flex tn-flex-row-center tn-flex-row-between">
				<view class="justify-content-item tn-padding-left-sm">
					日期
				</view>
				<view class="justify-content-item tn-text-center">
					体温
				</view>
				<view class="justify-content-item tn-padding-right-sm tn-text-right" style="width:80px">
					咽喉
				</view>
			</view>
		<view class="" v-if="datalist.length">
			<view class="itemv tn-flex tn-flex-row-center  tn-flex-row-between " v-for="(item, index) in datalist" :key="index">
				<view class="justify-content-item tn-padding-left-sm">
					{{item.recordTime}}
				</view>
				<view class="justify-content-item tn-text-center">
					<text v-if="item.throatType == 1">{{item.bodyTemperature}}度</text>
					<text v-else-if="item.throatType == 2" ><text style="color:#FFD392">{{item.bodyTemperature}}</text>度 </text>
					<text v-else="item.throatType == 3" style="color:#CC5A36"><text style="color:#CC5A36">{{item.bodyTemperature}}</text>度 </text>
				</view>
				<view class="justify-content-item tn-padding-right-sm tn-text-right" style="width:80px">
					<text v-if="item.throatType == 1" style="color: #01BEFF;">正常</text>
					<text v-else-if="item.throatType == 2" style="color:#FFD392">轻微炎症</text>
					<text v-else="item.throatType == 3" style="color:#CC5A36">严重炎症</text>
				</view>
			</view>
		</view>
		
		<view class="tn-padding-top" style="position: relative; height: 150rpx" v-else>
			 <customEmpty></customEmpty>
		</view>
		
		
		<tn-calendar
		  v-if="showcalendar"
		  v-model="showcalendar"
		  mode="date"
		  :changeYear="false"
		  :isChange="true"
		  @change="onChange"
		></tn-calendar>
	</view>
</template>

<script>
	import customEmpty from '../../components/customEmpty.vue'
	export default {
		name: 'youerruyuan',
		components:{customEmpty},
		data(){
			return {
				showcalendar:false,
				dangqianriqi: '',
				showcalendar:false,
				datalist: []
			}
		},
		onShow() {
			// for(let i=0;i<10;i++){
			// 	this.datalist.push({
			// 		riqi: i+1+'号',
			// 		tiwen: '37.5度',
			// 		yanhou: '正常'
			// 	})
			// }
			this.getDay(new Date())
			this.getList();
		},
		mounted() {
			
			this.getDay(new Date())
			this.getList();
		},
		methods: {
			getDay(dd){
				let y = dd.getFullYear();
			　　let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
				this.dangqianriqi = y+'-'+m;
			},
			onChange(event){
				console.log(event, event.date)
				this.dangqianriqi = event.year + '-' + event.month
				this.getList()
			},
			getNextDate(type){
				
			},
			showcalFunction(){
				this.showcalendar = true
			},
			/**获取上一个月 */
			getPreMonth() {
			    var arr = this.dangqianriqi.split("-");
			    var year = arr[0]; //获取当前日期的年份
			    var month = arr[1]; //获取当前日期的月份
			 
			    var year2 = year;
			    var month2 = parseInt(month) - 1;
			    if (month2 == 0) {
			        //1月的上一月是前一年的12月
			        year2 = parseInt(year2) - 1;
			        month2 = 12;
			    }
			 
			    if (month2 < 10) {
			        //10月之前都需要补0
			        month2 = "0" + month2;
			    }
			    this.dangqianriqi = year2 + "-" + month2;
				this.getList()
			},
			getNextMonth() {
			    var arr = this.dangqianriqi.split("-");
			    var year = arr[0]; //获取当前日期的年份
			    var month = arr[1]; //获取当前日期的月份
			    var day = arr[2]; //获取当前日期的日
			    
			    var year2 = year;
			    var month2 = parseInt(month) + 1;
			    if (month2 == 13) {
			        //12月的下月是下年的1月
			        year2 = parseInt(year2) + 1;
			        month2 = 1;
			    }
			    if (month2 < 10) {
			        //10月之前都需要补0
			        month2 = "0" + month2;
			    }
			 
			    this.dangqianriqi = year2 + "-" + month2;
				this.getList()
			},
			getClass(item, index){
				if(index % 2 == 0){
					return 'shuangshu'
				}
				return ''
			},
			
			getList(){
				let userInfo = uni.getStorageSync('userInfo');
				this.request({
					url: '/MCheck/GetMobilePage',
					method: 'get',
					params: {
						QueryTime: this.dangqianriqi,
						PageNo: 1,
						PageSize: 31,
						ChildrenId: userInfo.childId
					},
				}).then(res => {
					if(res.code == 200){
						this.datalist = res.data.rows
					}
				})
			},
			
			showcalFunction(){
				this.showcalendar = true
			},
		}
	}
</script>

<style lang="scss" scoped>
	.chenjian-body{
			min-height: 100vh;
			background-color: #EEF6EE;
			overflow-y: auto;
			position: relative;
	}
	.center-text-riqi{
		padding: 10rpx 28rpx;
		font-size: 36rpx;
		font-weight: bold;
	}
	.shuangshu{
		background-color: #fafafa;
	}
	.itemv{
		padding: 13rpx 20rpx;
		background-color: #ffffff;
	}
	.titlev{
		padding: 20rpx;
		background-color: #79CF67;
		border-radius: 16rpx 16rpx 0 0;
		color:#fff
	}
</style>